<%@ include file="../import_page.jsp"%>
<%
	//login checking
	if(!loginedChecking(session, UsersType.staff)) {
		//user don't login
		//redirect to home page
		response.sendRedirect(URL_HOMEPAGE);
		return;
	}
	
	//select unit check
	if(!selectUnitCheck(session)) {
		//if user didn't select an Unit
		//redirtect to select page
		response.sendRedirect(URL_SELECT_UNIT);
		return;
	}
	
	Users loginUser = (Users)session.getAttribute(SESSION_LOGIN_USER);
	Units selectUnit = (Units)session.getAttribute(SESSION_SELECT_UNIT);
	String errMsg = null;
	
	ArrayList<AssignmentCollector> listAss = null;
	//get assignment
	try {
		AssignmentsControl assCon = new AssignmentsControl();
		listAss = assCon.getAssignments(selectUnit.getId());
		assCon.closeDBConnection();
	} catch (Exception err) {
		errMsg = err.toString();
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Uni-Learn - Assignment Select</title>
<style type="text/css">
<!--
.style1 {
	font-size: large;
	font-weight: bold;
}

.style2 {
	font-size: large;
}
-->
</style>
<link rel="stylesheet" type="text/css" href="../img_style.css" />
<script type="text/javascript" src="<%= URL_JQUERY %>"></script>
<script type="text/javascript" src="<%= URL_VIEW_ASS_JS %>"></script>
</head>

<body>
	<table width="100%" border="1" align="left" bordercolor="#CCCCCC"
		bgcolor="#00FF99">
		<tr>
			<th colspan="8"><div align="center">
					<span class="style1">Staff Assignment Selection </span>
				</div>
			</th>
		</tr>
		<tr>
			<th rowspan="2">Name</th>
			<th rowspan="2">Individual / Group</th>
			<th rowspan="2">Deadline</th>
			<th rowspan="2">Full Mark</th>
			<th colspan="3">Status</th>
			<th rowspan="2">Marking Scheme</th>
		</tr>
		<tr>
			<th>Submission</th>
			<th>Marking</th>
			<th>Modify</th>
		</tr>
		<%
	if(listAss != null) {
		Iterator<AssignmentCollector> laI = listAss.iterator();
		AssignmentsControl aCon = new AssignmentsControl();
		while(laI.hasNext()) {
			AssignmentCollector ac = laI.next();
			ArrayList<AssignmentMaterial> listAm = aCon.getAssignmentMaterial(ac.getId());
%>
		<tr>
			<td><span class="style2"><a href="javascript:clickMoreAss(<%=ac.getId() %>);"><%= ac.getName() %></a>
			</span></td>
			<td><%= (ac.getGroupSize() < 2 ? "Individual" : ("Group (" + ac.getGroupSize()+ ")")) %></td>
			<td><%= formatDateTime(ac.getDeadline()) %></td>
			<td><%= ac.getFullMark().toString() %></td>
			<td><%= ac.isSubmission() ? IMG_YES : IMG_NO %></td>
			<td><a
				href="<%= addParmeterToUrl(URL_VIEW_SUBMITED, PAR_ASSIGNMENT_ID, Integer.toString(ac.getId())) %>"><%= ac.isMarking() ? IMG_YES + " Mark Now" : IMG_NO + IMG_VIEW %></a>
			</td>
			<td><a
				href="<%= addParmeterToUrl(URL_MODIFY_ASSIGNMENT, PAR_ASSIGNMENT_ID, Integer.toString(ac.getId())) %>"><%=IMG_MODIFY %></a>
			</td>
			<td><a
				href="<%= addParmeterToUrl(URL_VIEW_MS, PAR_ASSIGNMENT_ID, Integer.toString(ac.getId())) %>"><%=IMG_VIEW %></a>
				<a
				href="<%= addParmeterToUrl(URL_MODIFY_MS, PAR_ASSIGNMENT_ID, Integer.toString(ac.getId())) %>"><%=IMG_MODIFY %></a>
			</td>
		</tr>
		<tr>
			<td colspan="8">
			<div name="more_ass_<%=ac.getId() %>">
				<table width="90%" border="1" bordercolor="#CCCCCC"
					style="margin: 0 5%;">
					<tr>
						<td>Information:</td>
						<td><%= muiliteLineString(ac.getInfo()) %></td>
					</tr>
					<tr>
						<td>Material:<br /> <a
							href="<%= addParmeterToUrl(URL_MODIFY_AM, PAR_ASSIGNMENT_ID, Integer.toString(ac.getId())) %>"><%=IMG_MODIFY %></a>
						</td>
						<td>
							<%if(listAm.isEmpty()) { %> <%= IMG_NO %>No Material Provide <%
} else {
	Iterator<AssignmentMaterial> lamI = listAm.iterator();		
%>
							<table width="100%" border="1">
								<%
	while(lamI.hasNext()) {
		AssignmentMaterial am = lamI.next();
%>
								<tr>
									<td><%=am.getName() %><br /><%= am.getInfo() %><br /> <%		if(!isEmptyString(am.getFileName())) {
			Hashtable<String, String> keys = new Hashtable<String, String>(2);
			keys.put(PAR_ASSIGNMENT_ID, Integer.toString(ac.getId()));
			keys.put(PAR_AM_ORDER, Integer.toString(am.getOrder()));
%> <a href="<%=addParmeterToUrl(URL_DOWNLOAD_MATERIAL, keys)%>"><%=IMG_DOWNLOAD + am.getFileName()%></a>
										<%		} %>
									</td>
								</tr>
								<%	} %>
							</table> <%}%>
						</td>
					</tr>
				</table>
			</div>
			</td>
		</tr>
		<%
		}
		aCon.closeDBConnection();
	}
%>
	</table>
</body>
</html>
